package common;

public class Message implements Comparable<Message>{
	private byte[] data;
	private Entity source;
	private Entity dest;
	private int viewNum;
	private int seq;
	private long ticks;
	
	public Message(byte[] d) {
		data = d;
	}

	/**
	 * @return the data
	 */
	public byte[] getData() {
		return data;
	}

	/**
	 * @return the source
	 */
	public Entity getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(Entity source) {
		this.source = source;
	}

	/**
	 * @return the dest
	 */
	public Entity getDest() {
		return dest;
	}

	/**
	 * @param dest the dest to set
	 */
	public void setDest(Entity dest) {
		this.dest = dest;
	}

	/**
	 * @return the seq
	 */
	public int getSeq() {
		return seq;
	}

	/**
	 * @param seq the seq to set
	 */
	public void setSeq(int seq) {
		this.seq = seq;
	}
	
	public void setSendTime(long ticks)
	{
		this.ticks = ticks;
	}
	public long getSentTime()
	{
		return this.ticks;
	}
	
	@Override
	public boolean equals(Object o) {
		if(o.getClass().equals(Message.class)) {
			Message m = (Message) o;
			return((m.seq == seq) && m.source.equals(source));
		} else {
			return false;
		}
	}

	@Override
	public int compareTo(Message o) {
		return seq - o.seq;
	}

	public void setViewNum(int viewNum) {
		this.viewNum = viewNum;
	}

	public int getViewNum() {
		return viewNum;
	}

	public int hashCode(){
		int hash = 0;
		for(int i = 0; i < data.length; i ++){
			hash += data[i];
		}
		return hash * 3 + source.hashCode() * 7 + dest.hashCode() * 13; 
	}
}
